package com.example.muyonghui.mytimetable;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.widget.Toast;

/**
 * Created by muyonghui on 16/11/15.
 */
public class MyDatabaseHelper extends SQLiteOpenHelper {
    public static final String CREATE_USER = "create table user ("
            + "id integer primary key autoincrement, "
            + "username text, "
            + "password text,"
            + "name text,"
            + "code text,"
            + "school text,"
            + "class text,"
            + "sex text,"
            + "birth text,"
            + "zy text)";

    public static final String CREATE_COURSE = "create table course ("
            + "id integer primary key autoincrement, "
            + "username text, "
            + "course_name text, "
            + "course_address text, "
            + "course_teacher text, "
            + "course_time text)";


    private Context mContext;

    public MyDatabaseHelper(Context context, String name, SQLiteDatabase.CursorFactory factory, int version) {
        super(context, name, factory, version);
        mContext = context;
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL(CREATE_USER);
        db.execSQL(CREATE_COURSE);
        Toast.makeText(mContext, "Create succeeded", Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        db.execSQL("drop table if exists user");
        db.execSQL("drop table if exists course");
        onCreate(db);
    }
}
